package utils;

import org.openqa.selenium.firefox.FirefoxDriver;

import java.io.File;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.Dimension;
import org.openqa.selenium.Platform;
import org.openqa.selenium.UnexpectedAlertBehaviour;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.Assert;

/**
 * Created by sky_lady on 6/5/14.
 *public WebDriverFactory(String ) {
    }
 */


public class WebDriverFactory {

    /* Browsers constants */
    public static final String CHROME = "chrome";
    public static final String FIREFOX = "firefox";

    /* Firefox profiles */
    public static final String DEFAULT_PROFILE = "default";

    

    public WebDriverWrapper initDriver (String browser, String profileName)
    {
        WebDriverWrapper testDriver = setDefaultConfiguration(browser, profileName);
        return testDriver;
    }

    private WebDriverWrapper setDefaultConfiguration(String browser, String profileName)
    {
        WebDriver driver = null;

        if (browser.equals(FIREFOX))
        {
            driver = new FirefoxDriver();
        } else
        if (browser.equals(CHROME))
        {
            File file = new File(PropertyLoader.loadProperty("selenium.chrome.driver.path"));
            System.setProperty("webdriver.chrome.driver",file.getAbsolutePath());
            driver = new ChromeDriver();
        } else

        //additional configuration
        driver.manage().timeouts().implicitlyWait(Integer.parseInt(PropertyLoader.loadProperty("selenium.implicitly.wait")), TimeUnit.SECONDS);


        WebDriverWrapper testDriver = new WebDriverWrapper(driver);
        return testDriver;
    }


}
